/** * @package MauticJS * @copyright 2024 Mautic Contributors. All rights reserved. * @author Mautic * @link http://mautic.org * @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html */(function(){if(typeof window.CustomEvent==="function")return!1;function CustomEvent(event,params){params=params||{bubbles:!1,cancelable:!1,detail:undefined};var evt=document.createEvent('CustomEvent');evt.initCustomEvent(event,params.bubbles,params.cancelable,params.detail);return evt} CustomEvent.prototype=window.Event.prototype;window.CustomEvent=CustomEvent})();var MauticJS=MauticJS||{};MauticJS.serialize=function(obj){if('string'==typeof obj){return obj} return Object.keys(obj).map(function(key){return encodeURIComponent(key)+'='+encodeURIComponent(obj[key])}).join('&')};MauticJS.documentReady=function(f){/in/.test(document.readyState)?setTimeout(function(){MauticJS.documentReady(f)},9):f()};MauticJS.iterateCollection=function(collection){return function(f){for(var i=0;collection[i];i++){f(collection[i],i)}}};MauticJS.log=function(){var log={};log.history=log.history||[];log.history.push(arguments);if(window.console){console.log(Array.prototype.slice.call(arguments))}};MauticJS.setCookie=function(name,value){document.cookie=name+"="+value+"; path=/; secure"};MauticJS.createCORSRequest=function(method,url){var xhr=new XMLHttpRequest();method=method.toUpperCase();if("withCredentials" in xhr){xhr.open(method,url,!0)}else if(typeof XDomainRequest!="undefined"){xhr=new XDomainRequest();xhr.open(method,url)} return xhr};MauticJS.CORSRequestsAllowed=!0;MauticJS.makeCORSRequest=function(method,url,data,callbackSuccess,callbackError){data=MauticJS.appendTrackedContact(data);var query=MauticJS.serialize(data);if(method.toUpperCase()==='GET'){url=url+'?'+query;var query=''} var xhr=MauticJS.createCORSRequest(method,url);var response;callbackSuccess=callbackSuccess||function(response,xhr){};callbackError=callbackError||function(response,xhr){};if(!xhr){MauticJS.log('MauticJS.debug: Could not create an XMLHttpRequest instance.');return!1} if(!MauticJS.CORSRequestsAllowed){callbackError({},xhr);return!1} xhr.onreadystatechange=function(e){if(xhr.readyState===XMLHttpRequest.DONE){response=MauticJS.parseTextToJSON(xhr.responseText);if(xhr.status===200){callbackSuccess(response,xhr)}else{callbackError(response,xhr);if(xhr.status===XMLHttpRequest.UNSENT){MauticJS.CORSRequestsAllowed=!1}}}};if(typeof xhr.setRequestHeader!=="undefined"){if(method.toUpperCase()==='POST'){xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded')} xhr.setRequestHeader('X-Requested-With','XMLHttpRequest');xhr.withCredentials=!0} xhr.send(query)};MauticJS.parseTextToJSON=function(maybeJSON){var response;try{response=JSON.parse(maybeJSON)}catch(error){response=maybeJSON} return response};MauticJS.insertScript=function(scriptUrl){var scriptsInHead=document.getElementsByTagName('head')[0].getElementsByTagName('script');var lastScript=scriptsInHead[scriptsInHead.length-1];var scriptTag=document.createElement('script');scriptTag.async=1;scriptTag.src=scriptUrl;if(lastScript){lastScript.parentNode.insertBefore(scriptTag,lastScript)}else{document.getElementsByTagName('head')[0].appendChild(scriptTag)}};MauticJS.insertStyle=function(styleUrl){var linksInHead=document.getElementsByTagName('head')[0].getElementsByTagName('link');var lastLink=linksInHead[linksInHead.length-1];var linkTag=document.createElement('link');linkTag.rel="stylesheet";linkTag.type="text/css";linkTag.href=styleUrl;if(lastLink){lastLink.parentNode.insertBefore(linkTag,lastLink.nextSibling)}else{document.getElementsByTagName('head')[0].appendChild(linkTag)}};MauticJS.guid=function(){function s4(){return Math.floor((1+Math.random())*0x10000).toString(16).substring(1)} return s4()+s4()+'-'+s4()+'-'+s4()+'-'+s4()+'-'+s4()+s4()+s4()};MauticJS.dispatchEvent=function(name,detail){var event=new CustomEvent(name,{detail:detail});document.dispatchEvent(event)};function s4(){return Math.floor((1+Math.random())*0x10000).toString(16).substring(1)} MauticJS.mtcSet=!1;MauticJS.appendTrackedContact=function(data){if(window.localStorage){if(mtcId=localStorage.getItem('mtc_id')){data.mautic_device_id=localStorage.getItem('mautic_device_id')}} return data};MauticJS.getTrackedContact=function(){if(MauticJS.mtcSet){return} MauticJS.makeCORSRequest('GET',MauticJS.contactIdUrl,{},function(response,xhr){MauticJS.setTrackedContact(response)})};MauticJS.setTrackedContact=function(response){if(response.id){MauticJS.setCookie('mtc_id',response.id);MauticJS.setCookie('mautic_device_id',response.device_id);MauticJS.mtcSet=!0;try{localStorage.setItem('mtc_id',response.id);localStorage.setItem('mautic_device_id',response.device_id)}catch(e){console.warn('Browser does not allow storing in local storage')}}};MauticJS.postEventDeliveryQueue=[];MauticJS.firstDeliveryMade=!1;MauticJS.onFirstEventDelivery=function(f){MauticJS.postEventDeliveryQueue.push(f)};MauticJS.preEventDeliveryQueue=[];MauticJS.beforeFirstDeliveryMade=!1;MauticJS.beforeFirstEventDelivery=function(f){MauticJS.preEventDeliveryQueue.push(f)};document.addEventListener('mauticPageEventDelivered',function(e){var detail=e.detail;var isImage=detail.image;if(isImage&&!MauticJS.mtcSet){MauticJS.getTrackedContact()}else if(detail.response&&detail.response.id){MauticJS.setTrackedContact(detail.response)} if(!isImage&&typeof detail.event[3]==='object'&&typeof detail.event[3].onload==='function'){detail.event[3].onload(detail)} if(!MauticJS.firstDeliveryMade){MauticJS.firstDeliveryMade=!0;for(var i=0;i0&&!MauticJS.isPixelLoaded(!0)){maxChecks--;return} clearInterval(checkPixel);if(maxChecks>0){var params={},hash;var hashes=MauticJS.trackingPixel.src.slice(MauticJS.trackingPixel.src.indexOf('?')+1).split('&');for(var i=0;i and